# -*- coding: utf-8 -*-
# created on 2016/11/30
import copy

from mathsolver.functions.base import *
from mathsolver.functions.shulie.ShuLie_getSeqPoly import ShuLieGetSeqPoly


class ShuLieProveEq(BaseFunction):
    def solver(self, *args):
        eq = args[0].sympify()
        left = eq[0]
        right = eq[1]
        stepsolver1 = ShuLieGetSeqPoly(copy.deepcopy(self.known)).solver(BasePoly(left))
        self.steps += stepsolver1.steps
        self.label.update(stepsolver1.label)
        stepsolver2 = ShuLieGetSeqPoly(copy.deepcopy(self.known)).solver(BasePoly(right))
        self.steps += stepsolver2.steps
        self.label.update(stepsolver2.label)
        left_value = stepsolver1.output[0].sympify()
        right_value = stepsolver2.output[0].sympify()
        if len(left_value) == len(right_value):
            for index, lvalue in enumerate(left_value):
                rvalue = right_value[index]
                cha = (lvalue - rvalue).expand().simplify()
                if cha == 0:
                    self.steps.append(["", "∴等式成立"])
        self.label.add("证明数列等式成立")
        return self
